package com.qiwx.pigeon.fragment.query;

import android.content.Intent;
import android.database.Cursor;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.qiwx.pigeon.R;
import com.qiwx.pigeon.Utils.LogUtil;
import com.qiwx.pigeon.Utils.MyToast;
import com.qiwx.pigeon.Utils.ScreenUtils;
import com.qiwx.pigeon.data.vo.WareHouseBean;
import com.qiwx.pigeon.fragment.AbsQueryFragment;

import org.angmarch.views.NiceSpinner;
import org.litepal.LitePal;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

import static com.qiwx.pigeon.activity.common.SelectDateActivity.REQUEST_CODE_END;
import static com.qiwx.pigeon.activity.common.SelectDateActivity.REQUEST_CODE_START;

/**
 * @description
 * @Author qiwx
 * @Date 2020-03-28 10:52
 * 鸽仓情况查询
 * // TODO 鸽仓查询跟鸽场查询页面类似
 **/
public class QueryWareHouseFragment extends AbsQueryFragment {
    @BindView(R.id.spinner_wh)
    NiceSpinner spinnerWh;
    @BindView(R.id.txt_start_date)
    TextView txtStartDate;
    @BindView(R.id.txt_end_date)
    TextView txtEndDate;
    @BindView(R.id.btn_query)
    Button btnQuery;
    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;

    @BindView(R.id.btn_condition)
    Button btnCondition;


    @Override
    public int getLayoutId() {
        return R.layout.fragment_query_warehouse;
    }

    @Override
    public void initAfterOnCreate() {
        initView();


    }


    private void initView() {
        btnCondition.setVisibility(View.GONE);
        spinnerWh.setPadding(ScreenUtils.dip2px(getActivity(), 7), 0, 0, 0);
        initSpinner();
        //
    }

    private void initSpinner() {

        List<WareHouseBean> list = getWareHouses();
        List<String> data = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            data.add(list.get(i).getName());
        }
        spinnerWh.attachDataSource(data);
        spinnerWh.setOnSpinnerItemSelectedListener((parent, view, position, id) -> {
            MyToast.showCenterShort(list.get(position).getId() + "");

        });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case REQUEST_CODE_START:
                if (data != null && !TextUtils.isEmpty(data.getStringExtra("car_Time_MSG"))) {
                    txtStartDate.setText(data.getStringExtra("car_Time_MSG"));
                }
                break;
            case REQUEST_CODE_END:
                if (data != null && !TextUtils.isEmpty(data.getStringExtra("car_Time_MSG"))) {
                    txtEndDate.setText(data.getStringExtra("car_Time_MSG"));
                }
                break;
        }
    }


    @OnClick({R.id.spinner_wh, R.id.txt_start_date, R.id.txt_end_date, R.id.btn_query})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.spinner_wh:
                break;
            case R.id.txt_start_date:
                selectStartValiDate();
                break;
            case R.id.txt_end_date:
                selectEndValiDate(txtStartDate.getText().toString());
                break;
            case R.id.btn_query:

                break;
        }
    }
}
